package com.lanou.liuqixin.datebasedemo.custom;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by dllo on 17/5/12.
 */

public class Zhuzhuang extends View {
    private int[] values = new int[5];
    private String[] names = new String[6];
    private Paint mPaint;
    private static final int COUNT_X_MARK = 6 ;
    private static final int COUNT_Y_MARK = 6 ;


    //由此屏幕确定的值
    private static final int PANDING_WIDTH = 50;
    private static final int PANDING_HEIGHT = 150;
    private int mWidth;
    private int mHeight;

    public Zhuzhuang(Context context) {
        super(context);
        init();
    }

    public Zhuzhuang(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public Zhuzhuang(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        //测量出来屏幕宽度,高度
        mWidth = MeasureSpec.getSize(widthMeasureSpec);
        mHeight = MeasureSpec.getSize(heightMeasureSpec);


    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //画轴
        drawAxisX(canvas);
        drawAxisY(canvas);
        //画刻度
        drawMarkX(canvas);
        drawMarkY(canvas);

    }

    //X轴刻度
    private void drawMarkX(Canvas canvas) {
        float length = (mWidth - PANDING_WIDTH * 2) / COUNT_X_MARK ;
        for (int i = 0; i < COUNT_X_MARK; i++) {
            float startX = PANDING_WIDTH + length * (i + 1) ;
            float startY = mHeight - PANDING_HEIGHT - 20 ;
            float stopY = mHeight - PANDING_HEIGHT ;
            float stopX = startX ;
            canvas.drawLine(startX,startY,stopX,stopY,mPaint);

            Rect rect =new Rect(210,500,380,1230);
            canvas.drawRect(rect,mPaint);

        }
        for (int i1 = 0; i1 < names.length; i1++) {
            float x = PANDING_WIDTH+length * (i1 + 1) - 20 ;
            float y = mHeight - PANDING_HEIGHT + 20 ;
            mPaint.setTextSize(20);
            canvas.drawText(names[i1],x,y,mPaint);

        }




    }

    //Y轴刻度
    private void drawMarkY(Canvas canvas) {
    }


    //Y轴
    private void drawAxisY(Canvas canvas) {
        float startY = PANDING_HEIGHT;
        float stopY = mHeight - PANDING_HEIGHT;
        float startX = PANDING_WIDTH;
        float stopX = startX;
        mPaint.setColor(Color.BLACK);
        canvas.drawLine(startX,startY,stopX,stopY,mPaint);


    }

    //X轴
    private void drawAxisX(Canvas canvas) {
        float startX = PANDING_WIDTH;
        float startY = mHeight - PANDING_HEIGHT;
        float stopX = mWidth - PANDING_WIDTH;
        float stopY = startY;
        mPaint.setColor(Color.BLACK);
        canvas.drawLine(startX, startY, stopX, stopY, mPaint);


    }


    private void init() {
        values[0] = 10;
        values[1] = 30;
        values[2] = 60;
        values[3] = 50;
        values[4] = 20;

        names[0] = "一月份";
        names[1] = "二月份";
        names[2] = "三月份";
        names[3] = "四月份";
        names[4] = "五月份";
        names[5] = "六月份";

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);



    }


}
